import {getNotNull,dealStartEndDate,getFileTypeFile,getFileTypeFiles} from '@/views/util'
import {PROJECT_DIC} from '@/const/dict'
import {resultDetail} from "@/api/planning/result";
export default function () {
  return {
    data() {
      return {
        resultDetailData:[]
      }
    },
    methods: {
      // 获取成果详情
      async getDetailData_result(id){
        return new Promise((resolve, reject) => {
          resultDetail(id).then(async response => {
            var records = response.data.data
            let basisFile = await getFileTypeFile(records.basisFileId)
            let textFile = await getFileTypeFile(records.textId)
            let files = await getFileTypeFiles(records.fileId)
            let detailData = []
            detailData = [
              {label:'文号',value:getNotNull(records.releaseNo)},
              {label:'规划名称',value:getNotNull(records.title)},
              {label:'规划类型',value:getNotNull(records.category,PROJECT_DIC.CATEGORY),newline:true},
              {label:'规划期限',value: dealStartEndDate(records.startDate,records.endDate),newline:true},
              {label:'申报(牵头)单位',value:getNotNull(records.orgName),newline:true},
              {label:'规划等级',value:getNotNull(records.planningRank,PROJECT_DIC.PLANNING_RANK),newline:true},
              {label:'发布时间',value:getNotNull(records.releaseDate,null,'date'),newline:true},
              {label:'发布层级',value:getNotNull(records.planningLevel,PROJECT_DIC.PLANNING_LEVEL),newline:true},
              {label:'审批机关级别',value:getNotNull(records.approvingAuthorityLevel,PROJECT_DIC.APPROVING_AUTHORITY_LEVEL),newline:true},
              {label:'审批机关性质',value:getNotNull(records.approvingAuthorityNature,PROJECT_DIC.APPROVING_AUTHORITY_NATURE),newline:true},
              {label:'联系人姓名',value:getNotNull(records.contactName),newline:true},
              {label:'联系电话',value:getNotNull(records.contactNumber),newline:true},
              {label:'编制经费来源',value:getNotNull(records.financialSource)},
              {label:'立项依据',files:basisFile},
              {label:'主要内容',value:getNotNull(records.content)},
              {label:'规划文本',files:textFile},
              {label:'相关材料',files:files},
              {label:'是否公开',value:getNotNull(records.isOpen,PROJECT_DIC.isOpen,'isOpen')},
            ]
            if(records.state == '0'){
              detailData = detailData.map((v, index) => {
                if (v.label === '规划类型') {
                  return {
                    label: '(拟申报)规划类型',
                    value: v.value,
                    newline:true
                  }
                }
                if (v.label === '发布时间') {
                  return {
                    label: '(拟)发布时间',
                    value: v.value,
                    newline:true
                  }
                }
                if (v.label === '发布层级') {
                  return {
                    label: '(拟)发布层级',
                    value: v.value,
                    newline:true
                  }
                }
                return v;
              })
            }
            resolve(detailData)
          })
        })
      },
    }
  }
}
